package com.binhai.rolem;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author 18764
* @description 针对表【t_role】的数据库操作Service实现
* @createDate 2025-04-19 09:02:43
*/
@Service
public class RoleBeanServiceImpl extends ServiceImpl<RoleBeanMapper, RoleBean>
    {
        @Autowired
        private RoleBeanMapper roleBeanMapper;
        public List getAllInfos() {
            //selectList查询多条语句
            return roleBeanMapper.selectList(null);
        }

        public Map saveInfo(RoleBean role) {
            Map map = new HashMap();
            try {
                //插入数据
                roleBeanMapper.insert(role);
                map.put("result","success");
                return map;
            }
            catch (Exception e){
                e.printStackTrace();
                map.put("result","error");
                return map;
            }
        }

        public Map deleteInfo(int id) {
            Map map = new HashMap();
            try {
                //根据id删除数据
                roleBeanMapper.deleteById(id);
                map.put("result","success");
                return map;
            }
            catch (Exception e){
                e.printStackTrace();
                map.put("result","error");
                return map;
            }
        }

        public Map updateInfo(RoleBean role) {
            Map map = new HashMap();
            try {
                //通过id修改
                roleBeanMapper.updateById(role);
                map.put("result","success");
                return map;
            }
            catch (Exception e){
                e.printStackTrace();
                map.put("result","error");
                return map;
            }
        }

        public RoleBean getInfoById(int id) {

            return roleBeanMapper.selectById(id);
        }
    }



